
clear
set more off


cap log close
log using $logdir/amendment_timing.log, replace

use $fromsasdir/amendments, clear

gen any_ertc = ertc_amendment > 0
gen year = floor(tp/100)

gcollapse (max) max_am = ertc_amendment (sum) any_ertc ertc_amendment, by(year ext_year ext_mo) fast

qui replace ertc_amendment = ertc_amendment/10^9

gen tc_date = ym(ext_year,ext_mo)
format tc_date %tm

gen ratio = max_am*10^-9/ertc_amendment
sum ratio if any_ertc >= 5


twoway line ertc_amendment tc_date if year == 2020 & any_ertc >= 5 & ratio <= 0.4, lcolor(gs0) || ///
    line ertc_amendment tc_date if year == 2021 & any_ertc >= 5 & ratio <= 0.4, lcolor(gs0) lpattern("--") ///
        legend(order(1 "2020Q2-2020Q4" 2 "2021Q3-2021Q4")) scheme(s1color) ///
        ytitle("Amount of ERC on amended return (bil)") ///
        xtitle("Month of amendment processing")




qui save $outdir/amendment_timing, replace
gen d2022 = tc_date >= tm(2022m1)

sum d2022 [aw=ertc_amendment]
list


cap log close

